package com.yztstudy.Controller;

import com.yztstudy.Service.CollectService;
import com.yztstudy.entity.Collect;
import com.yztstudy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收藏的表示层
 */

@RestController
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    /**
     * TODO 添加收藏
     * @param collect 收藏对象
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody Collect collect)
    {
        return collectService.save(collect);
    }


    /**
     * TODO 根据用户id查询他收藏的商品的id集合
     * @param collect 传入的用户id
     * @return
     */
    @PostMapping("/list")
    public R list(@RequestBody Collect collect)
    {
        return collectService.list(collect);
    }


    /**
     * TODO 删除收藏
     * @param collect 包含了用户ID和商品ID
     * @return
     */
    @PostMapping("/remove")
    public R remove(@RequestBody Collect collect)
    {
        return collectService.remove(collect);
    }


    /**
     * TODO 删除收藏里面的商品
     * @param productId 商品Id
     * @return
     */
    @PostMapping("/removeByProductId")
    public R removeByProductId(@RequestBody Integer productId)
    {
        return collectService.removeByProductId(productId);
    }
}
